﻿
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Ymt.Repository;
using YmtRpc.Domain;
using YmtRpc.Domain.Enum;


namespace YmtRpc.Web.Admin.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult Index(FormCollection collection)
        {
            DependencyRelationEnum dependencyRelation = (DependencyRelationEnum)Convert.ToInt32(collection["dependencyRelation"]);
            string appId = collection["appid"];
            ServiceDependencyQueryCondition cond = new ServiceDependencyQueryCondition()
            {
                DependencyRelation = dependencyRelation,
                AppId = appId
            };

            // 构建服务的依赖树
            List<ServiceDependencyNode> zNodes = RepositoryHub.ServiceDependencySamplingRepository.PopulateDependencyTree(cond);

            return Json(zNodes);
        }

        [HttpGet]
        public JsonResult GetAppIdListByDependencyRelation()
        {
            DependencyRelationEnum dependencyRelation = (DependencyRelationEnum)Convert.ToInt32(Request.QueryString["dependencyRelation"]);
            List<string> appIdList = RepositoryHub.ServiceDependencySamplingRepository.GetAppIdListByDependencyRelation(dependencyRelation);

            return Json(appIdList, JsonRequestBehavior.AllowGet);
        }
    }
}
